<?php
include 'format.php';
FormatHeader();
function Mno_user(&$username){
	echo '<h1> Username does not exist </h1>';
	echo_log();
	$username=false;
	return false;
}
$WPOJ_Is_Logged = 0;
if ($_COOKIE["user"] && $_COOKIE["password"]){
	mysql_connect("localhost", "root", "apache") or die(mysql_error());
	mysql_select_db("jobs") or die(mysql_error());
	$username=true;
	//echo $_COOKIE["user"].$_COOKIE["password"];
	//echo "SELECT * FROM users where user = '".$_COOKIE["user"]."'";
	$result = mysql_query("SELECT * FROM users where user = '".$_COOKIE["user"]."'") or die(mysql_error()); 
	$row = mysql_fetch_array( $result ) or Mno_user($username);
	if ($username == true){
		if ($_COOKIE["password"]){
			$encryptpass = $_COOKIE["password"];
			if ($encryptpass == $row['password']){
				echo '<a href="/logout.php">Log Out</a><br>';
				echo $row['user'].'<br><hr>';
				$WPOJ_Is_Logged = 1;
				$WPOJ_User = $row['user'];
				$WPOJ_Rank = $row['rights'];
				if ($row['rights'] > 0){
					if ($row['rights'] == 2){
						// pun ce apare la admini
						# forum admin
						echo '<a href="/reeval.php">reevaluate submissions</a><br>';
						echo '<a href="/forum/adm">forum admin</a><br>';
						echo '<a href="/addcontest.php">add contest</a><br><hr>';
					}
					echo '<a href="/addproblem.php">add problem</a><br>';
					echo '<a href="/uploadfiles.php">upload files</a><br>';
					echo '<a href="/myproblemlist.php">problem list</a><br><hr>';					
					// pun ce apare la admini + helperi
				}
				echo '<a href="/myaccount.php">my account</a><br>';
				// pun ce apare la toti
				echo '<br>';
			}
			else
				echo_unreg();
		}
		else
			echo_unreg();
	}
	else
		echo_unreg();
}
else
	echo_unreg();
echo '
	<a href="/status.php">status</a><br>
	<a href="/submit.php">submit</a><br>
	<a href="/problems.php">problems</a><br><br>
	<a href="/">news</a><br>
	<a href="/contests.php">contests</a><br>
	<a href="/ranks.php">ranks</a><br><br>
	<a href="/forum">forum</a><br>
	<a href="/help.php">help</a><br><hr></div><div class="time">
Server time:
</div>
<div class="time">';
echo date("Y-m-d");
echo '<br><b>';
echo date("H : m : s");
echo '</b>
</div>
</td><td class="content" width="99%">
<p align="justify">';

if ($WPOJ_Rank == 2){

$String2 = "update job set Status = 0 ";
$String3 = "update job set Points = 0 ";

 $Ok = 0;
	$WPOJ_FILTER_USER = $_GET['user']; 
	if($WPOJ_FILTER_USER){
		$Ok = 1;
		$String = $String."where user = '".$WPOJ_FILTER_USER."' ";
	}
	$WPOJ_FILTER_TASK = $_GET['task'];	
	if ($WPOJ_FILTER_TASK){
		if ($Ok == 0){
			$Ok = 1;
			$String = $String."where problem = '".$WPOJ_FILTER_TASK."' ";
		}
		else{
			$String = $String."and problem = '".$WPOJ_FILTER_TASK."' ";
		}
	}	
	$WPOJ_FILTER_CONTEST = $_GET['contest'];
	if ($WPOJ_FILTER_CONTEST){
		if ($Ok == 0){
			$Ok = 1;
			$String = $String."where contest = '".$WPOJ_FILTER_CONTEST."' ";
		}
		else{
			$String = $String."and contest = '".$WPOJ_FILTER_CONTEST."' ";
		}
	}
	
	$WPOJ_FILTER_Score_begin = $_GET['score_begin'];
	if ($WPOJ_FILTER_Score_begin){
		if ($Ok == 0){
			$Ok = 1;
			$String = $String."where Points >= ".$WPOJ_FILTER_Score_begin." ";
		}
		else{
			$String = $String."and Points >= ".$WPOJ_FILTER_Score_begin." ";
		}
	}
	
	$WPOJ_FILTER_Score_end = $_GET['score_end']; 
	if ($WPOJ_FILTER_Score_end){
		if ($Ok == 0){
			$Ok = 1;
			$String = $String."where Points <= ".$WPOJ_FILTER_Score_end." ";
		}
		else{
			$String = $String."and Points <= ".$WPOJ_FILTER_Score_end." ";
		}
	}
	
	if ($Ok != 0){
		mysql_connect("localhost", "root", "apache") or die(mysql_error());
		mysql_select_db("jobs") or die(mysql_error());
		$result = mysql_query($String2.$String) or die(mysql_error()); 
		$result = mysql_query($String3.$String) or die(mysql_error()); 
		echo '<h1> The sources are been regraded now. </h1>';
	}
	else
		echo '<h1> Please filter submissions. </h1>';
}
else{
	echo '<h1> You don\'t have enough rights to access this page. I will redirect you in 5 seconds.... </h1>
	<meta HTTP-EQUIV="REFRESH" content="5; url=http://localhost">';
	
}
FormatFooter();
?>

